<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>综合练习</title>
    <style>
        td {
            width: 100px
        }
    </style>
</head>
<body>
<table border="1">
    <caption>个人详情</caption>
    <tr>
        <td>照片:</td>
        <td id="pic_td"></td>
    </tr>
    <tr>
        <td>姓名:</td>
        <td id="name_td"></td>
    </tr>
    <tr>
        <td>年龄:</td>
        <td id="age_td"></td>
    </tr>
    <tr>
        <td>好友:</td>
        <td id="friend_td"></td>
    </tr>
</table>
<input type="button" value="加载数据" onclick="f()">
<script>
    // 得到页面中的所有td
    let picTd = document.querySelector("#pic_td");
    let nameTd = document.querySelector("#name_td");
    let ageTd = document.querySelector("#age_td");
    let friendTd = document.querySelector("#friend_td");

    function f() {
        // 模拟从服务器得到的数据
        let person = {name: "雷神", age: 18, imgURL: "./images/雷神.jpg", friends: ["八重神子", "布耶尔", "钟离"]}
        nameTd.innerText = person.name;
        ageTd.innerText = person.age;
        let img = document.createElement("img");
        img.src = person.imgURL;
        img.width = 100;
        picTd.append(img);
        let ul = document.createElement("ul");
        // 遍历
        for (const friendName of person.friends){
            let li = document.createElement("li");
            li.innerText = friendName;
            ul.append(li);
        }
        friendTd.append(ul);
    }
</script>
</body>
</html>